#ifndef OPERATOR_R
#define OPERATOR_R
//=========================================================
// MATRIX OF OPERATOR R
//=========================================================
struct R_matrix{
  char *name;
  int dim_l;
  int dim_c;
  int **r_m;
};
//=========================================================
int dim_R = 0; //dimension of the R-cube
//=========================================================
// print R //
void print_R(R_matrix *R){
  for(int i=0; i<dim_R; i++){
    printf("NAME: %s LINES: %d COLUMNS: %d\n",R[i].name,R[i].dim_l,R[i].dim_c);
    for(int j=0; j<R[i].dim_l; j++){
      for(int k=0; k<R[i].dim_c; k++){
        printf("%d ",R[i].r_m[j][k]);
      }
      printf("\n");
    }
    printf("\n");
  }
}
//---------------------------------------------------------
// get_source //
R_matrix *get_R(const char *filename){
  R_matrix *R;
  FILE *fi;
  fi = fopen(filename,"r");
  if(fi == NULL){
    perror("Error: opening file source");
    R = NULL;
  }else{   
    int dim_l,dim_c,**r_m;
    char *name;
    fscanf(fi,"%i\n",&dim_R);
    R = new R_matrix[dim_R];
    for(int i=0; i<dim_R; i++){
      name = new char[30];
      fscanf(fi,"%s %i %i\n",name,&dim_l,&dim_c);
      r_m = new int*[dim_l];
      for(int j=0; j<dim_l; j++) 
        r_m[j] = new int[dim_c];
      for(int j=0; j<dim_l; j++){
        for(int k=0; k<dim_c; k++){
          r_m[j][k] = fgetc(fi) - '0';
        }
        fgetc(fi);
      }
      R[i].name = name;
      R[i].dim_l = dim_l;
      R[i].dim_c = dim_c;
      R[i].r_m = r_m;
    }
    fclose(fi);
  }
  return R;
}
//---------------------------------------------------------
// load_source //
R_matrix *load_source(const char *filename){
	R_matrix *R = NULL;
	R = get_R(filename);
  printf("R dimension = %d\n",dim_R);
  print_R(R);
  printf("--------------------------------------------\n");
  return R;
}
//=========================================================
#endif